﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SqlconTest
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        public static string constr = "Server=.;user Id=sa;pwd=123456;database=Test;";
        public static SqlConnection sqlcon = new SqlConnection(constr);

        private void Form2_Load(object sender, EventArgs e)
        {
            if (sqlcon.State == ConnectionState.Closed)
            {
                sqlcon.Open();
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //int id = Convert.ToInt32(this.textBox1.Text);
            string name = this.textBox2.Text;
            string sql = "insert into StuInfo values('" + name + "')";
            SqlCommand command = new SqlCommand(sql,sqlcon);
            int result = command.ExecuteNonQuery();
            if (result>=1)
            {
                MessageBox.Show("增加成功");
                this.Close();
            }
            else
            {
                MessageBox.Show("增加失败");
            }
        }
        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
